Skip to content

Replace <literal> nodes with <constant> for constants - #2310

Merged
kamil-tekiela merged 1 commit into
php:masterfrom
phansys:constants
Sep 25, 2026
Merged

kamil-tekiela merged 1 commit into
php:masterfrom
phansys:constants

Conversation

@phansys

@phansys phansys commented Feb 18, 2023 •

Copy link
Copy Markdown
Contributor

172 occurrences were replaced from <literal>([A-Za-z0-9_]+)::([A-Z0-9_\*]+)</literal> to <constant>$1::$2</constant>.

See #2306 (comment).

TODO:

@phansys
phansys marked this pull request as ready for review February 18, 2023 12:19

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this, this makes sense.

However, I'd wait a bit to check with translations as this does do some busy work for them (and as I'm being on the French translation and the constant tag does not generates links it would be nice that I can tackle more urgent stuff)

@Girgias

Girgias commented Feb 20, 2023

Copy link
Copy Markdown
Member

It would make sense to coordinate this with #1963 also to not repeat the work multiple times.

@phansys

phansys commented Feb 20, 2023

Copy link
Copy Markdown
Contributor Author

Great! Let me inherit these changes here and mark the other PR in a TO-DO list in order to make the dependency explicit.

@phansys
phansys force-pushed the constants branch 2 times, most recently from b950b26 to bae3592 Compare February 20, 2023 16:58
@phansys
phansys requested a review from Girgias February 20, 2023 19:01
@Girgias Girgias added the QA Quality Assurance label Mar 9, 2023
@phansys
phansys force-pushed the constants branch 2 times, most recently from b8da203 to 21eb6eb Compare August 25, 2023 02:36

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall OK but I'm going to wait to merge this as this is a QA change.

Also it would be nice to fix the whitespaces in another PR that one can skip-revcheck as those clutter the PR.

@Girgias Girgias added this to the QA improvements milestone Aug 30, 2023
@phansys

phansys commented Aug 31, 2023

Copy link
Copy Markdown
Contributor Author

Also it would be nice to fix the whitespaces in another PR that one can skip-revcheck as those clutter the PR.

Whitespace changes were reverted 👍

@Girgias

Girgias commented Apr 17, 2024

Copy link
Copy Markdown
Member

Sorry for the delay in this, could you rebase the PR on master?

@phansys

phansys commented Apr 17, 2024

Copy link
Copy Markdown
Contributor Author

Rebased.

@haszi

haszi commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

There are a few constants with replaceable parts that use _XXX instead of _*. Do you think it would make sense to add those to this PR?

These are the ones I've found in doc-en:

CURL_VERSION_XXX
CURLM_XXX
CURLOPT_XXX
IMAGETYPE_XXX
PNG_FILTER_XXX
SOAP_PERSISTENCE_XXX
TIDY_TAG_XXX
VT_XXX

@phansys

phansys commented Apr 17, 2024

Copy link
Copy Markdown
Contributor Author

I think these are missing cases @haszi. Thank you for pointing.
Let me check if I can find a consistent way to catch them and I'll update the PR.

@phansys

phansys commented Apr 17, 2024

Copy link
Copy Markdown
Contributor Author

The cases using the _XXX suffix were addressed.

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the runkit changes are appropriate, nor the Enumeration docs as those refer to inline examples, maybe using code is more appropriate but I need to have a think about this.

Copilot AI lite review requested due to automatic review settings September 24, 2026 23:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kamil-tekiela

Copy link
Copy Markdown
Member

You can drop the changes to the migrated extensions. It will make reviewing this easier too.

The only limitation is that the <literal>class</literal> keyword still
cannot be used as a constant name, otherwise it would conflict with the
class name resolution syntax (<literal>ClassName::class</literal>).
class name resolution syntax (<constant>ClassName::class</constant>).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a constant. It shuld stay as literal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<para>
The special <constant>::class</constant> constant allows
for fully qualified class name resolution at compile time,
this is useful for namespaced classes:
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, it is also called a magic constant here https://www.php.net/manual/en/language.constants.magic.php

However, I don't think we are going for semantics here. The change is about making the constants link up properly, and magic "constant" ::class cannot do that. So, using <constant> is not useful here. Compare how it is rendered right now on https://www.php.net/manual/en/migration70.other-changes.php or https://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class

Comment thread language/oop5/basic.xml Outdated
name resolution.
To obtain the fully qualified name of a class <literal>ClassName</literal>
use <literal>ClassName::class</literal>. This is particularly useful with
use <constant>ClassName::class</constant>. This is particularly useful with

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Comment thread language/enumerations.xml Outdated
This declaration creates a new enumerated type named <literal>Suit</literal>, which has
four and only four legal values: <literal>Suit::Hearts</literal>, <literal>Suit::Diamonds</literal>,
<literal>Suit::Clubs</literal>, and <literal>Suit::Spades</literal>. Variables may be assigned
four and only four legal values: <constant>Suit::Hearts</constant>, <constant>Suit::Diamonds</constant>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are constants.

Comment thread language/enumerations.xml Outdated
The <literal>query()</literal> function can now proceed safe in the knowledge that
<literal>$order</literal> is guaranteed to be either <literal>SortOrder::Asc</literal>
or <literal>SortOrder::Desc</literal>. Any other value would have resulted in a
<literal>$order</literal> is guaranteed to be either <constant>SortOrder::Asc</constant>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

&reftitle.returnvalues;
<para>
Returns an <literal>IntlChar::PROPERTY_</literal> constant value,
Returns an <constant>IntlChar::PROPERTY_</constant> constant value,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are missing replaceable here.

@kamil-tekiela
kamil-tekiela merged commit 9c73659 into php:master Sep 25, 2026
2 of 3 checks passed
@phansys
phansys deleted the constants branch September 25, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Quality Assurance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants